package file;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import data.Data;

public class Parsing3ClassesW2Inputs {
	List<Data> list = new ArrayList<Data>();
	List<Data> pos = new ArrayList<Data>();
	List<Data> neu = new ArrayList<Data>();
	List<Data> neg = new ArrayList<Data>();
	
	double pavg;
	double navg;
	
	public Parsing3ClassesW2Inputs(String data, String svm1, String svm2, double margin ) throws IOException {

		BufferedReader dataReader = new BufferedReader(new FileReader(data));
		BufferedReader svm1Reader = new BufferedReader(new FileReader(svm1));
		BufferedReader svm2Reader = new BufferedReader(new FileReader(svm2));
		String line;
		double psum = 0.0;
		int pnum = 0;
		
		double nsum = 0.0;
		int nnum = 0;
		
		int znum = 0;
		
		while((line = dataReader.readLine()) != null){
			String[] field = line.split(",");
			int uid = Integer.parseInt(field[0]);
			short iid = Short.parseShort(field[1]);
			byte rat = Byte.parseByte(field[2]);
			
			Data datum = new Data(uid, iid, rat);
			list.add(datum);
			
			String line2 = svm1Reader.readLine();
			double margin1 = Double.parseDouble(line2);
			
			if(margin1 > 0) {
				if(margin1 > margin) {
					pos.add(datum);
				}
				else{
					neu.add(datum);
				}
			}
			else {
				String line3 = svm2Reader.readLine();
				double margin2 = Double.parseDouble(line3);
				
				if(margin2 > margin){
					neg.add(datum);
				}
				else {
					neu.add(datum);
				}
			}
		}
		
		dataReader.close();
		svm1Reader.close();
		svm2Reader.close();
	}

	public List<Data> getList() {
		return list;
	}

	public List<Data> getPos() {
		return pos;
	}

	public List<Data> getNeu() {
		return neu;
	}

	public List<Data> getNeg() {
		return neg;
	}

	public double getPavg() {
		return pavg;
	}

	public double getNavg() {
		return navg;
	}

}
